//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __AURA_PRIVATE_H_
#define __AURA_PRIVATE_H_

#include "auratypes.h"

#ifdef _DEBUG
#   if defined(_GNUC)
#       define FixMe(statement) Aura_printf("[FixMe]<%s>"#statement"\n", __FUNCTION__);
#   elif defined(_MSVC)
#       define FixMe(statement) Aura_printf("[FixMe]<%s>"##statement##"\n", __FUNCTION__);
#   else
#       error unsupported compiler.
#   endif
#else
#   define FixMe(statement)
#endif

#ifndef NULL
#   define NULL 0
#endif

#ifdef _GNUC
#   if defined(_x86)
#       define Aura_DebugBreak() do { __asm("int $3"); } while(0)
#   elif defined(_arm)
#       define Aura_DebugBreak() { __asm(".long 0xef9f0001;");}
#   else
#       error unsupported architecture.
#   endif
#else
#   error unsupported compiler
#endif

#undef assert
#ifdef _DEBUG
void __cdecl _assert(const char *exp, const char *fn, int ln);
#define assert(exp) do { \
                        if (exp) { \
                            (void)0; \
                        } else { \
                            _assert(#exp, __FILE__, __LINE__); \
                            Aura_DebugBreak(); \
                        } \
                    } while(0)
#else
#define assert(exp)
#endif

#define START_LOCK(hLock) do {AuraCriticalSection_Enter(hLock);}while(0)
#define END_LOCK(hLock)   do {AuraCriticalSection_Leave(hLock);}while(0)

#define SIG_ABORTTHREAD 12 //SIGUSR2

//Another DBG_FLAG defined in linux_low.c
#define DBG_FLAG "-ELDBG"

typedef struct _ThreadDescr
{
    int           m_threadId;
    Aura_Handle   m_hStartEvent;
    Aura_Handle   m_hQuitEvent;

    //Aura_Address  m_rawStack;
    //Aura_Int32    m_rawStackSize;
    //Aura_Address  m_desktop;

    Aura_Bool     m_bMainThread;
}ThreadDescr;

Aura_ECode GetLastAuraECode();

int InfiniteFilter(Aura_Millisecond32 timeOut);

int AuraMemoryMapFlagsConvertToLinux(Aura_MemoryMapFlags flags);
int AuraMemoryProtectionConvertToLinux(Aura_MemoryProtection protect);
Aura_ThreadPriority ConvertToAuraPriority(/* [in]  */ int priority);
int ConvertToLinuxPriority(/* [in]  */ Aura_ThreadPriority priority);

#endif // __AURA_PRIVATE_H_

